#!/bin/ksh

PATH=$PATH:/usr/bin:/usr/sbin:/usr/lpp/netscape/navigator/dt/bin

#Defect 260812
unset CLASSPATH

DT_REMOTE=`whence dtremotenscp`
DB=`whence defaultbrowser`
NETSCAPE=`whence netscape`

if [[ -n "$3" ]]; then
    export LANG=$3
fi

HELP_URL="$1"
shift

echo "$HELP_URL" | grep ^file: > /dev/null
FILERC=$?

rc=0


if [[ $FILERC -eq 0 ]] ; then
  #
  # This is a file:/ url.  We must attempt to launch the
  # browser to load the file since we cannot be sure that 
  # a browser running on the client's display was started 
  # from this host.
  #
  
  if [[ -n "$DB" ]] ; then
    #Try the default browser

    $DB "$HELP_URL" $* && exit 0
  fi

  if [[ -n "$NETSCAPE" ]] ; then
    #Try netscape
  
    $NETSCAPE "$HELP_URL" && exit 0
  fi

  #
  # If we got to here it means the default browser and netscape
  # commands failed.  Change the file: into a url and try again.
  #

  HELP_URL=$(echo "$HELP_URL" | sed "s!file:/usr/share/man/info/!http://$(hostname)/doc_link/!") 
fi
  
  
    


if [[ -n "$DT_REMOTE" && -n "$DB" ]]; then

  $DB "$HELP_URL" $* && exit 0

elif [[ -n "$NETSCAPE" ]]; then

  $NETSCAPE -remote "openURL($HELP_URL,new-window)"  && exit 0
  
  # If the above command fails, try without the -remote
  $NETSCAPE $HELP_URL  && exit 0

fi


# If we get here, we couldn't open any browser
echo $HELP_URL
exit 1
